package com.hecore.lagou.work.oneReducer;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @Author: hecore
 * @Date: 2020/10/19 00:50
 * @Description: 单个Reducer的实现类
 *  输出 当前第几个排序数据;数字按从小到大顺序排序
 */

public class OneReducerReducer extends Reducer<IntWritable, IntWritable, IntWritable, IntWritable> {

    /**
     * 声明全局num
     */
    int num=1;

    /**
     * 单个Reducer的reducer方法
     * @param key
     * @param values
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void reduce(IntWritable key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
        for (IntWritable value : values){
            context.write(new IntWritable(num), value);
            num=++num;
        }
    }
}

